package com.byxy.shop.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.shop.dao.UserDao;
import com.byxy.shop.entity.User;
import com.byxy.shop.service.UserService;
import com.byxy.ssm.shop.vo.UserVO;

/**
 * @author 廖善椅
 * @ClassName UserServiceImpl
 * @Description 业务实现类
 * @date 2020年5月17日
 */

@Service
@Transactional
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public User login(String loginName, String password) {
		
		return userDao.selectByNameAndPassword(loginName, password);
	}

	@Override
	public User save(User user) {
		// 先查询
		if(userDao.getByName(user.getLoginName()).size() == 0) {
			// 保存
			int id = userDao.save(user);
			if(id > 0) {
				return userDao.getById(user.getUserId());
			}
		}
		
		return null;
	}

	@Override
	public int updateUserInfo(User user) {
		UserVO uTemp = new UserVO();
		uTemp.setUserId(user.getUserId());
		uTemp.setNickName(user.getNickName());
		uTemp.setAddress(user.getAddress());
		uTemp.setIntroduceSign(user.getIntroduceSign());
		return userDao.updateByPrimaryKeySelective(user);
	}

	@Override
	public User getById(Integer userId) {
		return userDao.getById(userId);
	}

}
